/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.N000;
import queenb.net.entitybean.N250;
import queenb.web.store.N250Store;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class N250Controller extends QueenbController {

    private int pn250;
    private String pv251;
    private String pv252;
    private String pv253;
    private N250Store n250Store;

    public N250Controller() {
        n250Store = new N250Store();

        Object pn250oObject = getRequest().getParameter("pn250");
        if (pn250oObject != null) {
            this.pn250 = Util.parseInt(pn250oObject);
            getDetailEditN850(pn250);
        }
    }

    public void updateN250() {
        try {
            int row = n250Store.updateN250(pn250, pv251, pv252, pv253, getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            if (row > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {

                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
            sendRedirectUrlTab("setting.jsp?tab=header15&link15="+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }

    public List<N250> getListAllN250() {

        try {

            List<N250> list = n250Store.getListN250(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            return list;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }

    public void getDetailEditN850(int id) {
        try {
            List<N250> listN850Edit = getListAllN250();
            if (listN850Edit.size() > 0) {
                for (int i = 0; i < listN850Edit.size(); i++) {
                    if (listN850Edit.get(i).getPn250() == id) {
                        System.out.println("------------->>" + listN850Edit.get(i).getNv251());
                        this.pv251 = listN850Edit.get(i).getNv251();
                        this.pv253 = listN850Edit.get(i).getNv253();
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }

    /**
     * @return the pn250
     */
    public int getPn250() {
        return pn250;
    }

    /**
     * @param pn250 the pn250 to set
     */
    public void setPn250(int pn250) {
        this.pn250 = pn250;
    }

    /**
     * @return the pv251
     */
    public String getPv251() {
        return pv251;
    }

    /**
     * @param pv251 the pv251 to set
     */
    public void setPv251(String pv251) {
        this.pv251 = pv251;
    }

    /**
     * @return the pv252
     */
    public String getPv252() {
        return pv252;
    }

    /**
     * @param pv252 the pv252 to set
     */
    public void setPv252(String pv252) {
        this.pv252 = pv252;
    }

    /**
     * @return the pv253
     */
    public String getPv253() {
        return pv253;
    }

    /**
     * @param pv253 the pv253 to set
     */
    public void setPv253(String pv253) {
        this.pv253 = pv253;
    }
}
